<!-- -->
<template>
  <div class="public">
    <div class="con">
      <div class="userInfo">
        <dl>
          <dt>
            <img :src="list.img" alt />
          </dt>
          <dd>
            <div class="info">
              <span>{{ list.phone }}</span>
              <p>{{list.roles}}:{{ list.name }}</p>
            </div>
            <p>
              <van-icon name="arrow" />
            </p>
          </dd>
        </dl>
      </div>

      <div class="main">
        <ul>
          <li class="main-boxOne" v-if="auth('5')">
            <span>预约管理</span>
            <p>
              <van-icon name="arrow" />
            </p>
          </li>
          <li class="main-boxOne" v-if="auth('6')">
            <span>我的回答</span>
            <p>
              <van-icon name="arrow" />
            </p>
          </li>
          <li class="main-boxOne" v-if="auth('1')">
            <span>我的关注</span>
            <p>
              <van-icon name="arrow" />
            </p>
          </li>
          <li class="main-boxOne" v-if="auth('2')">
            <span>我的提问</span>
            <p>
              <van-icon name="arrow" />
            </p>
          </li>
          <li class="main-boxOne" v-if="auth('3')">
            <span>我的点评</span>
            <p>
              <van-icon name="arrow" />
            </p>
          </li>
          <li class="main-boxOne" v-if="auth('4')">
            <span>我的预约</span>
            <p>
              <van-icon name="arrow" />
            </p>
          </li>
        </ul>
      </div>
      <div class="blank"></div>
      <ol>
        <li class="main-boxTwo">
          <span>我的出租房</span>
          <p>
            <van-icon name="arrow" />
          </p>
        </li>
        <li class="main-boxTwo" @click="jumpInfo">
          <span>我的二手房</span>
          <p>
            <van-icon name="arrow" />
          </p>
        </li>
        <li class="main-boxTwo">
          <span>我的写字楼</span>
          <p>
            <van-icon name="arrow" />
          </p>
        </li>
        <li class="main-boxTwo">
          <span>我的商铺</span>
          <p>
            <van-icon name="arrow" />
          </p>
        </li>
        <li class="main-boxTwo" @click="jumpInfoList">
          <span>我的消息列表</span>
          <p>
            <van-icon name="arrow" />
          </p>
        </li>
      </ol>

      <div class="btn">
        <button @click="gun">退出登录</button>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserInfo } from "@/api";
import { myList } from "@/data/myList.js";
import { auth } from "@/utils/index";
export default {
  name: "my",
  // import引入到组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      listOne: myList,
      token: null,
      list: {},
      auth //为了让这个方法走一遍完整的生命周期
    };
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监听data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    getUser() {
      getUserInfo({ token: this.token }).then(res => {
        console.log(res);
        // 存入身份
        this.list = res.data;
      });
    },
    gun() {
      this.$toast("退出成功");
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
    jumpInfo() {
      this.$router.push("/myoldhouse");
    },
    jumpInfoList() {
      this.$router.push("/infoPage");
    }
  },
  //生命周期 - 创建完成 (可以访问当前this实例)
  created() {
    this.token = localStorage.getItem("token");
    this.getUser();
    auth();
  },
  //生命周期 - 挂载完成 (可以访问DOM元素)
  mounted() {}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style lang="scss" scoped>
.con {
  flex: 1;
  overflow: auto;
}
.userInfo {
  width: 100%;
  height: 120px;
  padding: 20px;
  background: #e4e4e4;
  dl {
    display: flex;
    dt {
      width: 58px;
      height: 58px;
      border: 1px solid black;
      border-radius: 50%;
      img {
        width: 57px;
        height: 57px;
        border-radius: 50%;
      }
    }
    dd {
      margin-left: 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex: 1;
      .info {
        span {
          font-size: 18px;
        }
        p {
          display: flex;
          justify-content: center;
          font-size: 13px;
          margin-top: 10px;
          border: 1px solid black;
          border-radius: 5px;
          padding: 2px;
        }
      }
      p {
        font-size: 25px;
      }
    }
  }
}

.main {
  width: 100%;
  height: auto;
}
.blank {
  width: 100%;
  height: 15px;
  background: #f2f2f2;
}

.main-boxOne {
  display: flex;
  align-items: center;
  width: 100%;
  height: 45px;
  padding: 15px;
  border-bottom: 1px solid #ccc;
  span {
    flex: 1;
  }
}

.main-boxTwo {
  display: flex;
  align-items: center;
  width: 100%;
  height: 45px;
  padding: 15px;
  border-bottom: 1px solid #ccc;
  span {
    flex: 1;
  }
}
.btn {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
}
.btn > button {
  margin-top: 15px;
  width: 291px;
  height: 40px;
  background: inherit;
  background-color: rgba(255, 255, 255, 1);
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-color: rgba(223, 223, 223, 1);
  border-radius: 5px;
}
</style>
